/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Action;
import Model.CusModel;
import bean.Product;
import ActionForm.SearchProForm;
import Model.ProModel;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author cpn02
 */
public class SearchProAction extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        SearchProForm spf = (SearchProForm)form;
        int minSize = Integer.parseInt( spf.getMinSize());
        int maxSize = Integer.parseInt(spf.getMaxSize());
        int cat = Integer.parseInt(spf.getCat());
        int page = Integer.parseInt(spf.getPage());
        int amount = Integer.parseInt(spf.getAmount());
        int gender = Integer.parseInt(spf.getGender());
        int startIndex = amount * (page-1)+1;
        ArrayList<Product> pros = new ArrayList<Product>();
        pros = ProModel.getProsBySearchCon(minSize, maxSize, gender, cat, startIndex, amount);
        request.setAttribute("searchResultPros", pros);
        return mapping.findForward("success");
    }


}
